<template>
  <div class="登录背景">
    <div class="激励语">
      <div>仲夏麦飘香，</div>
      <div>又逢高考时。</div>
    </div>
    <div class="登录组件">
      <div class="输入框组件">
        <div class="输入框信息">账户</div>
        <input
          type="text"
          class="输入框 登录输入框"
          placeholder="请输入证件号或手机号"
          v-model="form.id"
        />
      </div>
      <div class="输入框组件">
        <div class="输入框信息">密码</div>
        <input
          type="password"
          class="输入框 登录输入框"
          placeholder="请输入密码"
          v-model="form.pwd"
        />
      </div>
      <button class="登录按钮" @click="login()">登录</button>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
import { ElMessage } from "element-plus";
export default {
  data() {
    return {
      form: {
        id: "",
        pwd: "",
      },
    };
  },
  methods: {
    login() {
      if (this.form.id === "") {
        ElMessage({
          type: "error",
          message: "请输入用户名",
        });
      } else if (this.form.pwd === "") {
        ElMessage({
          type: "error",
          message: "请输入密码",
        });
      } else {
        request.post("/mentor/login.php", this.form).then((res) => {
          if (res.code === "200") {
            ElMessage({
              type: "success",
              message: "登录成功",
            });
            localStorage.setItem("zyh_tch_id", res.data.tch_id);
            localStorage.setItem("zyh_tch_name", res.data.tch_name);
            this.$router.push("/TchCourse");
          } else {
            ElMessage({
              type: "error",
              message: res.msg,
            });
          }
        });
      }
    },
  },
};
</script>

<style>
.登录背景 {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f6f6f6;
  background-image: url(../assets/背景-登录.png);
  background-repeat: no-repeat;
  background-position: bottom;
}
.激励语 {
  top: 15%;
  left: 8%;
  position: absolute;
  font-size: 22px;
  line-height: 40px;
  color: #d8800f;
}
.登录组件 {
  display: flex;
  align-items: center;
  flex-direction: column;
  flex-wrap: wrap;
  justify-content: center;
  position: relative;
  font-size: 14px;
}
.输入框组件 {
  width: 260px;
  height: 45px;
  margin-bottom: 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  background-color: #fff;
  color: #666666;
}
.输入框信息 {
  padding: 0 10px;
  border-right: 1px solid #666666;
  line-height: 14px;
}
.登录输入框 {
  margin-left: 15px;
}
.登录按钮 {
  width: 125px;
  height: 50px;
  margin-top: 30px;
  border: none;
  background-color: #f5611c;
  border-radius: 4px;
  color: #fff;
}
</style>